package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.InvoiceDetailInfo;

public interface InvoiceDetailInfoRepository extends JpaRepository<InvoiceDetailInfo, String> {

	@Query("select i from InvoiceDetailInfo i where i.sInvoiceTotalId.id=?1 ")
	List<InvoiceDetailInfo> findAllBysInvoiceTotalId(String id);
	
	@Query("select p.nInvoiceDetailPrice from InvoiceDetailInfo p where p.sContractId = ?1")
    float[] getnInvoiceDetailPrice(String contractId);

	@Query("select p from InvoiceDetailInfo p where p.sContractId = ?1 and p.sContractType=?2 and p.sCreateUserId=?3 ")
	Page<InvoiceDetailInfo> getInvoiceDetailInfoHistory(String contractId, String contractType, String userId,
			Pageable pageable);

	@Query("select p from InvoiceDetailInfo p where p.sContractId = ?1 and p.sContractType=?2 ")
	Page<InvoiceDetailInfo> getInvoiceDetailInfoAllHistory(String contractId, String contractType, Pageable pageable);

	@Query("select count(*) from InvoiceDetailInfo p where p.sContractId = ?1 and p.sContractType=?2 and p.sCreateUserId=?3 ")
	Long getInvoiceDetailInfoHistoryCount(String contractId, String contractType, String userId);

	@Query("select count(*) from InvoiceDetailInfo p where p.sContractId = ?1 and p.sContractType=?2 ")
	Long getInvoiceDetailInfoAllHistory(String contractId, String contractType);

	@Query("select p.nInvoiceDetailPrice from InvoiceDetailInfo p where p.sContractId = ?1 ")
	float[] getPaymentSum(String contractId);
}
